﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>客户费用详情</title>
    <!--<link href="../../script/css/bootstrap.css" rel="stylesheet" />
    <link href="../../script/css/bootstrap-theme.css" rel="stylesheet" />
    <link href="../../script/css/select2.css" rel="stylesheet" />
    <link href="../../script/css/bootstrap-datetimepicker.css" rel="stylesheet" />
    <script src="../../script/js/jquery-1.12.3.js"></script>
    <script src="../../script/js/bootstrap.js"></script>
    <script src="../../script/js/select2.full.js"></script>
    <script src="../../script/js/bootstrap-datetimepicker.js"></script>
    <script src="../../script/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../../script/js/cus-edit.js"></script>-->
</head>
<body>
    <div>
        <form>

            <div class='row'>

                <div class='col-md-6'>
                    <label>类别</label>
                    <select class='form-control' name='type' data-type='select'></select>
                </div>

                <div class='col-md-6'>
                    <label>类型</label>
                    <select class='form-control' name='type2' data-type='select'></select>
                </div>
            </div>

            <div class='row'>

                <div class='col-md-6'>
                    <label>公司</label>
                    <select class='form-control' name='companyid' data-type='select'></select>
                </div>

                <div class='col-md-6'>
                    <label>日期</label>
                    <input type='text' class='form-control datetimepicker' data-date-format='yyyy-mm-dd hh:ii' name='edate' data-type='date'>
                </div>
            </div>

            <div class='row'>

                <div class='col-md-6'>
                    <label>金额</label>
                    <input class='form-control' name='amount' data-type='text' />
                </div>

                <div class='col-md-6'>
                    <label>提成金额</label>
                    <input class='form-control' name='preceamount' data-type='text' />
                </div>
            </div>

            <div class='row'>
                <div class='col-md-6'>
                    <label>返点金额</label>
                    <input class='form-control' name='rebateamount' data-type='text' />
                </div>
            </div>

            <div class='row'>

                <div class='col-md-6'>
                    <label>最后修改人</label>
                    <input class='form-control' name='filler' data-type='text' />
                </div>

                <div class='col-md-6'>
                    <label>最后修改时间</label>
                    <input type='text' class='form-control datetimepicker' data-date-format='yyyy-mm-dd hh:ii' name='filldate' data-type='date'>
                </div>
            </div>

            <div class='row'>

                <div class='col-md-12'>
                    <label>备注</label>
                    <textarea class='form-control' name='remark' data-type='text'></textarea>
                </div>

                <div class='col-md-6' style="display:none;">
                    <label>订单</label>
                    <input class='form-control' name='orderid' data-type='text' />
                </div>
            </div>
        </form>
        <div style="margin-top:1em;display:none;">
            <button class="btn btn-primary" onclick="order_account_wl_editFrm.ok();">确定</button>
            <button class="btn btn-default" onclick="order_account_wl_init.back()">取消</button>
        </div>
    </div>
    <script>
        var order_account_wl_edit;

        var order_account_wl_editFrm = {
            ok: function () {
                //order_account_wl_edit.refObj()
                //console.log(JSON.stringify(order_account_wl_edit.refObj()));
                if (order_account_wl_init.getObj_edit() == null) {
                    var obj = order_account_wl_edit.refObj();
                    obj.orderid = order_main_init.getId_detail_edit();
                    $.post('/api/order_account_wl/add', obj, function () {
                        window.location.reload();
                    });
                } else {
                    $.post('/api/order_account_wl/edit', order_account_wl_edit.refObj(), function () {
                        window.location.reload();
                    });
                }
            }
        }

        $(function () {
            $('select[name="type2"]').change(null, function () {
                if ($('select[name="type2"]').val() == 1) {
                    $('input[name="amount"]').val(order_account_wl.data.yunfei_val);
                    $('select[name="companyid"]').change();
                }
                if ($('select[name="type2"]').val() == 2) {
                    $('input[name="amount"]').val(order_account_wl.data.baofei_val);
                    //$('input[name="preceamount"]').val(0);
                    $('select[name="companyid"]').change();
                }
            });

            $('select[name="companyid"]').change(null, function () {
                if ($('select[name="type2"]').val() == 1) {
                    var val = 0;
                    for (var i = 0; i < order_account_wl.data.companyid.length; i++) {
                        var p = order_account_wl.data.companyid[i];
                        if (p.id == $('select[name="companyid"]').val()) {
                            val = order_account_wl.data.yunfei_val * p.perce;
                            $('input[name="preceamount"]').val(val);
                        }
                    }
                }
                var val = 0;
                for (var i = 0; i < order_account_wl.data.companyid.length; i++) {
                    var p = order_account_wl.data.companyid[i];
                    if (p.id == $('select[name="companyid"]').val()) {
                        for (k = 0; k < p.rebate.length; k++) {
                            q = p.rebate[k];
                            if (q.code == $('select[name="type2"]').val()) {
                                val = $('input[name="amount"]').val() * q.rebate;
                            }
                        }
                        $('input[name="rebateamount"]').val(val);
                    }
                }
            });

            order_account_wl_edit = cusEdit();
            order_account_wl_edit.init({
                data: order_account_wl.data,
                editObj: order_account_wl_init.getObj_edit()
            });
            order_account_wl_edit.initEdit();

            if (order_account_wl_init.getObj_edit() == null) {
                if ($('select[name="type2"]').val() == 1) {
                    $('input[name="amount"]').val(order_account_wl.data.yunfei_val);
                    if (order_account_wl.data.companyid.length > 0) {
                        $('input[name="preceamount"]').val(order_account_wl.data.yunfei_val * order_account_wl.data.companyid[0].perce);
                        var p = order_account_wl.data.companyid[0];
                        var val = 0;
                        $('input[name="rebateamount"]').val(0);
                        for (k = 0; k < p.rebate.length; k++) {
                            q = p.rebate[k];
                            if (q.code == 1) {
                                val = $('input[name="amount"]').val() * q.rebate;
                                $('input[name="rebateamount"]').val(val);
                            }
                        }
                    }
                }
            }
        })
    </script>
</body>
</html>
